package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksPicture;
import com.ruoyi.books.service.IBooksPictureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗图片汇总Controller
 *
 * @author ruoyi
 * @date 2024-04-01
 */
@Anonymous
@RestController
@RequestMapping("/books/picture")
public class BooksPictureController extends BaseController
{
    @Autowired
    private IBooksPictureService booksPictureService;

    /**
     * 查询非遗图片汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksPicture booksPicture)
    {
        startPage();
        List<BooksPicture> list = booksPictureService.selectBooksPictureList(booksPicture);
        return getDataTable(list);
    }

    /**
     * 导出非遗图片汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:export')")
    @Log(title = "非遗图片汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksPicture booksPicture)
    {
        List<BooksPicture> list = booksPictureService.selectBooksPictureList(booksPicture);
        ExcelUtil<BooksPicture> util = new ExcelUtil<BooksPicture>(BooksPicture.class);
        util.exportExcel(response, list, "非遗图片汇总数据");
    }

    /**
     * 获取非遗图片汇总详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:query')")
    @GetMapping(value = "/{pictureId}")
    public AjaxResult getInfo(@PathVariable("pictureId") Long pictureId)
    {
        return success(booksPictureService.selectBooksPictureByPictureId(pictureId));
    }

    /**
     * 新增非遗图片汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:add')")
    @Log(title = "非遗图片汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksPicture booksPicture)
    {
        return toAjax(booksPictureService.insertBooksPicture(booksPicture));
    }

    /**
     * 修改非遗图片汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:edit')")
    @Log(title = "非遗图片汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksPicture booksPicture)
    {
        return toAjax(booksPictureService.updateBooksPicture(booksPicture));
    }

    /**
     * 删除非遗图片汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:picture:remove')")
    @Log(title = "非遗图片汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pictureIds}")
    public AjaxResult remove(@PathVariable Long[] pictureIds)
    {
        return toAjax(booksPictureService.deleteBooksPictureByPictureIds(pictureIds));
    }
}
